using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Pool;

public abstract class BasePool<T> : SingletonMono<BasePool<T>> where T : class
{
    [SerializeField]
    protected T prefab;
    [SerializeField]
    int defaultSize = 100;
    [SerializeField]
    int maxSize = 500;

    ObjectPool<T> pool;
    public void Initialize(bool collectionCheck = true) =>
        pool = new ObjectPool<T>(createFunc: OnCreatePoolItem, actionOnGet: OnGetPoolItem, actionOnRelease: OnReleasePoolItem, 
            actionOnDestroy: OnDestroyPoolItem, collectionCheck: collectionCheck, defaultSize, maxSize);

    protected abstract T OnCreatePoolItem();
    protected abstract void OnGetPoolItem(T obj);
    protected abstract void OnReleasePoolItem(T obj);
    protected abstract void OnDestroyPoolItem(T obj);

    public T Get() => pool.Get();
    public void Release(T obj) => pool.Release(obj);
    public void Clear() => pool.Clear();
}
